<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Search Extends MY_Controller
{

	private $current_session_user;
	private $auth_to_delete_student;
	private $link_to_view_fees;
	private $view_student_data;
	
	public function __construct()
	{
		parent::__construct();
		//laod acl_config
		$this->config->load('acl_config');
		$this->page_auth->secure_page($this->config->item('secure_page_search'));
		$this->link_to_view_fees = $this->config->item('auth_link_to_view_fees');
		$this->view_student_data = $this->config->item('view_subject_grade');
		$this->auth_to_delete_student = $this->config->item('auth_to_delete_student');
		$this->auth_enrollment_transaction_slip = $this->config->item('enrollment_transaction_slip');
		$this->auth_applicant_status = $this->config->item('applicant_status');
		$this->auth_applicant_interview = $this->config->item('applicant_interview');
		$this->applicant_recieve_payment = $this->config->item('applicant_recieve_payment');
		$this->applicant_update_payment = $this->config->item('applicant_update_payment');
		$this->print_assessment = $this->config->item('print_assessment');
		$this->print_pre_assessment = $this->config->item('print_pre_assessment');
		$this->print_assessment_or = $this->config->item('print_assessment_or');
		$this->enrollment_registrar = $this->config->item('enrollment_registrar');
		$this->student_reservation_payment = $this->config->item('student_reservation_payment');
		$this->current_session_user = strtolower($this->session->userdata('userType'));
		$this->session->set_flashdata('from',$this->router->method);
		$this->load->model('M_search','ms');
		$this->load->model('M_levels','ml');
		$this->load->model('M_applicants','ma');
		$this->load->model('M_assessment_fees','maf');
		$this->view_data['system_message'] = $this->_msg();
		$this->view_data['hash_for_link'] = $this->hs->encrypt(time());
		$this->_init_pagnate_config();
		
		$this->view_data['url'] = str_replace('/','-',uri_string());
		if(in_array($this->current_session_user,$this->auth_to_delete_student))
		{
			$this->view_data['delete'] = TRUE;
		}else{
			$this->view_data['delete'] = FALSE;
		}
	}
	
	/*-----------------------------------
		inquiry student
	-----------------------------------*/
	public function inquiries($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$total = $this->ms->count_inquiries($where);

		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_inquiries(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/inquiries');
			}
			
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/inquiries/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config['uri_segment'] = 4;
			$this->pagnate_config['total_rows'] = $total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->get_inquiries($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
		}
	
		$this->view_data['total'] = $total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;
	}
	
	/*-----------------------------------
		applicant or new student
	-----------------------------------*/
	public function applicants($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$total = $this->ms->count_applicants($where);
		
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_applicants(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/applicants');
			}
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/applicants/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] = $total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->get_applicants($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
		}

		$this->view_data['print_reservation_or'] = FALSE;
		$this->view_data['reserves'] = $this->maf->get_reserved();
		$this->view_data['levels'] = $this->ml->get_all_levels_array();
		$this->view_data['total'] = $total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;		
	}
	
	/*--------------------------------------
		applicant for registrar approval
	--------------------------------------*/
	public function enrollees($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$total = $this->ms->count_approved_enrollees($where);
		
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_approved_enrollees(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/enrollees');
			}
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/enrollees/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] = $total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->approved_enrollees($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
		}
		
		$this->view_data['reserves'] = $this->maf->get_reserved();
		$this->view_data['levels'] = $this->ml->get_all_levels_array();
		$this->view_data['total'] = $total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;	
	}

	/*--------------------------------------
		applicant for payment
	--------------------------------------*/
	public function registrar_approved($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$total = $this->ms->count_registrar_approved($where);
		
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_registrar_approved(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/registrar_approved');
			}
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/registrar_approved/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] =  $total;
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->registrar_approved($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
		}
		
		$this->view_data['levels'] = $this->ml->get_all_levels_array();
		$this->view_data['total'] = $total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;
	}
	
	/*--------------------------------------
		officially student
	--------------------------------------*/
	public function enrolled($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$total = $this->ms->count_approved_enrolled($where);
		
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_approved_enrolled(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/registrar_approved');
			}
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/enrolled/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] = $total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->approved_enrolled($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
		}
		
		$this->view_data['levels'] = $this->ml->get_all_levels_array();
		$this->view_data['total'] = $total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;
	}
	
	public function bonafide_students()
	{
		if($this->input->post('search'))
		{
			$search_items = (object)$this->input->post('search_string_item');
			$this->view_data['students'] = $this->ms->search_bonafide_students($search_items);
			$this->view_data['links'] = NULL;
			
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/bonafide_students';
			$this->pagnate_config['per_page'] = 30;
			$this->pagnate_config["uri_segment"] = 3;
			$this->pagnate_config['total_rows'] = $this->ms->count_bonafide_students();
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
			$this->view_data['students'] = 	$this->ms->bonafide_students($this->pagnate_config['per_page'],$page);
			
			$this->view_data['links'] = $this->pagination->create_links();
			
		}
		$this->view_data['levels'] = $this->ml->get_all_vp_levels_array();
		$this->_links();	
	}
	
	/*--------------------------------------------------------------
		Students with balance
	----------------------------------------------------------------*/
	function balance($letter = 'a')
	{

		$a_z = range('a','z');
		$letter = in_array($letter,$a_z) ? $letter : 'a';
		$this->load->library('pagination');
		$this->pagnate_config['base_url'] = base_url().'search/balance/'.$letter;
		$this->pagnate_config['per_page'] = 30;
		$this->pagnate_config["uri_segment"] = 3;
		$this->pagnate_config['total_rows'] = $this->ms->count_student_with_balance($letter);
		
		$this->pagination->initialize($this->pagnate_config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		$this->view_data['students'] = 	$this->ms->student_with_balance($this->pagnate_config['per_page'],$page,$letter);
		
		$this->_links();
		$this->view_data['links'] = $this->pagination->create_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $letter;	
	
	}
	
	public function deleted_enrollee($where = 'all')
	{
		//create a-z links
		$a_z = range('a','z');
		//add all to first 
		array_unshift($a_z, 'all');
		
		$where = in_array($where,$a_z) ? $where : 'all';
		$count_total = $this->ms->count_deleted_enrollees($where);
		
		if($this->input->post('search'))
		{
			$student = $this->input->post('student_search_data',TRUE);
			$f_student = strpos($student,'-') > 0 ? explode('-',$student) : FALSE;
			if($f_student){
				$this->view_data['students'] = $this->ms->search_deleted_enrollee(FALSE,$f_student[0]);
				$this->view_data['links'] = NULL;
			}else{
				redirect('search/deleted_enrollee');
			}
			
		}else{
			$this->load->library('pagination');
			$this->pagnate_config['base_url'] = base_url().'search/deleted_enrollee/'.$where;
			$this->pagnate_config['per_page'] = 10;
			$this->pagnate_config["uri_segment"] = 4;
			$this->pagnate_config['total_rows'] = $count_total;
			
			$this->pagination->initialize($this->pagnate_config);
			
			$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
			$this->view_data['students'] = 	$this->ms->deleted_enrollees($this->pagnate_config['per_page'],$page,$where);
			
			$this->view_data['links'] = $this->pagination->create_links();
			
		}
		
		$this->view_data['total'] = $count_total;
		$this->_links();
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $where;
	}

	public function enrollmentlist()
	{
		$this->load->model('M_levels','ml');
		$this->view_data['gls'] = $this->ml->get_all_levels();
		$this->view_data['students'] = $this->ms->default_masterlist('default');
		$this->view_data['hash'] = $this->hs->encrypt(time());
	}
	
	public function foreign()
	{
		$this->load->model('M_levels','ml');
		$this->view_data['gls'] = $this->ml->get_all_levels();
		$this->view_data['students'] = $this->ms->default_masterlist('foreign');
		$this->view_data['hash'] = $this->hs->encrypt(time());
		
	}
	
	public function nonforeign()
	{
		$this->load->model('M_levels','ml');
		$this->view_data['gls'] = $this->ml->get_all_levels();
		$this->view_data['students'] = $this->ms->default_masterlist('nonforeign');
		$this->view_data['hash'] = $this->hs->encrypt(time());
	}
	
	public function del($hash='',$url = FALSE)
	{
		$x = $this->hs->decrypt($hash);
		$fname = $this->session->userdata('e_f_name');
		$lname = $this->session->userdata('e_l_name');

		if(IS_AJAX)
		{
			$rfd = $this->input->post('reason_for_delete');
			if($x && $rfd)
			{
				$e_id = $x[0];
				
				$this->load->model('M_fees','mf');

				//if($this->mf->check_if_paid($e_id) == FALSE)
				//{
					$this->load->model('M_enrollees');
					$res = $this->M_enrollees->delete_enrollee($e_id,$rfd);
					

					// pd($res.' '.$url);
					if($res == TRUE)
					{
						$this->logger('login','Enrollment ID {'.$e_id.' was successfully deleted by '.$fname.','.$lname.'}. {'.$rfd.'}');
						$ret = 1;
					}else{
						$this->logger('login','Enrollment ID {'.$e_id.' was not successfully deleted by '.$fname.','.$lname.'}. Unable to delete record.');
						$ret = 0;
					}
				//}else{
					//$this->logger('login','Enrollment ID {'.$e_id.' was not successfully deleted by '.$fname.','.$lname.'}. Student already has payment record.');
					//$ret = 2;
				//}
			}else{
				$this->logger('login','Enrollment ID {'.$e_id.' was not successfully deleted by '.$fname.','.$lname.'}. No reason.');
				$ret = 1;
			}

			header('Content-Type: application/json');
			echo json_encode($ret);
			exit();
		}else{
		
			if($x AND $url)
			{
				$e_id = $x[0];
				
				
				$f_url = strpos($url,'-') !== FALSE ? str_replace('-','/',$url) : $url;
				
				$this->load->model('M_fees','mf');

				if($this->mf->check_if_paid($e_id) == FALSE)
				{
					$this->load->model('M_enrollees');
					$res = $this->M_enrollees->delete_enrollee($e_id);
					

					// pd($res.' '.$url);
					if($res == TRUE)
					{
						$this->logger('login','Enrollment ID {'.$e_id.' was successfully deleted by '.$fname.','.$lname.'}. {'.$rfd.'}');
						$this->_msg('s','Student data was successfully deleted.',$f_url);
					}else{
						$this->logger('login','Enrollment ID {'.$e_id.' was not successfully deleted by '.$fname.','.$lname.'}. Unable to delete student.');
						$this->_msg('e','Unable to delete student.',$f_url);
					}
				}else{
					$this->logger('login','Enrollment ID {'.$e_id.' was not successfully deleted by '.$fname.','.$lname.'}. Student already has payment record.');
					$this->_msg('e','Unable to delete student. Student already has payment record.',$f_url);
				}
				
			}else{
				show_error('Unable to process supplied URL.Page not found',404);
			}
		}

	}
	
	public function by($type = 'lastname',$lastname = 'a')
	{
		$a_z = range('a','z');
		$this->load->helper('misc');
		$this->view_data['is_finance'] = in_array($this->current_session_user, ['finance','cashier']);
		if($lastname && $type)
		{
			if(in_array($lastname,$a_z) && in_array(strtolower($type),['lastname','firstname','default']))
			{
				$this->load->library('pagination');


				$this->pagnate_config['full_tag_open'] = '<div class="pagination"><ul>';
				$this->pagnate_config['num_links'] = 4;
				// $this->pagnate_config['display_pages'] = FALSE;
				$this->pagnate_config['base_url'] = base_url().'search/by/'.$type.'/'.$lastname;
				$this->pagnate_config['per_page'] = 12;
				$this->pagnate_config["uri_segment"] = 5;
				

				$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
				$this->load->model(['M_student','M_levels']);
				$this->view_data['assign'] = TRUE;
				$students = $this->M_student->get_students_with($lastname,$type,$this->pagnate_config['per_page'],$page);
				$this->view_data['students'] = $students->result;
				$this->pagnate_config['total_rows'] = $students->count;
				$this->view_data['levels'] = $this->M_levels->get_all_levels_array(FALSE);


				$this->pagination->initialize($this->pagnate_config);
				$this->view_data['pagnatelinks'] = $this->pagination->create_links();

			}else{
				redirect('registrar/by/');
			}
		}else{
			$this->view_data['assign'] = FALSE;
			$this->view_data['students'] = FALSE;
		}

		$this->view_data['links'] = $a_z;
		$this->view_data['active'] = $lastname;
		$this->view_data['p_link'] = $this->router->class.'/'.$this->router->method.'/'.$type;
		$this->view_data['active_type'] = $type;

	}
	
	private function _links($delete = TRUE,$finance = TRUE,$student = TRUE)
	{
		if(in_array($this->current_session_user,$this->auth_to_delete_student) AND $delete)
		{
			$this->view_data['delete_link'] = function($var,$url){
												return '<li><a href="'.site_url('search/del/'.__link($var)).'/'.$url.'" class="confirm" title="Are you sure you want to delete student data?">Delete</a></li>';
											  };
		}else{
			$this->view_data['delete_link'] = function($var){ return NULL; };
		}
		
		//view fees links
		if(in_array($this->current_session_user,$this->link_to_view_fees) AND $finance)
		{
			$this->view_data['finance_link'] = function($e_id){return '<li><a href="'.site_url('fees/view_fees/'.$e_id).'">View Fees</a></li>';};
		}else{
			$this->view_data['finance_link'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->view_student_data))
		{
			if($student)
			{
				$this->view_data['student_link'] = function($e_id){return '<li><a href="'.site_url('profile/student/'.$e_id).'">Profile</a></li>
						<li><a href="'.site_url('profile/student_grade/'.$e_id).'">View Class Card/Grades</a></li>
						<li><a href="'.site_url('profile/student_schedule/'.$e_id).'">Schedule</a></li>';};
			}else{
				$this->view_data['student_link'] = 
						function($e_id){
							return '<li><a href="'.site_url('profile/student/'.$e_id).'">Profile</a></li>';
						};
			}
		}else{
			$this->view_data['student_link'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->auth_applicant_status))
		{
			$this->view_data['applicant_status'] = function($e_id){return '<li><a href="'.site_url('applicant/update_status/'.$e_id).'">Applicant Status</a></li>';};
		}else{
			$this->view_data['applicant_status'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->auth_applicant_interview))
		{
			$this->view_data['applicant_interview'] = function($e_id){return '<li><a href="'.site_url('applicant/update_interview/'.$e_id).'">Applicant Interview</a></li>';};
		}else{
			$this->view_data['applicant_interview'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->applicant_recieve_payment))
		{
			$this->view_data['applicant_recieve_payment'] = function($e_id){return '<li><a href="'.site_url('applicant/assessment_fee/'.$e_id).'">Assessment Fee Payment Center</a></li>';};
		}else{
			$this->view_data['applicant_recieve_payment'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->applicant_recieve_payment))
		{
			$this->view_data['print_assessment'] = function($e_id){return '<li><a href="'.site_url('pdf/assessment_fee/'.$e_id).'" target="_blank">Print Assessment Receipt</a></li>';};
		}else{
			$this->view_data['print_assessment'] = function($b){return NULL;};
		}
		
		if(in_array($this->current_session_user,$this->applicant_recieve_payment))
		{
			$this->view_data['print_pre_assessment'] = function($e_id){return '<li><a href="'.site_url('pdf/assessment_fee_form/'.$e_id).'" target="_blank">Print New Student Assessment & Application Form</a></li>';};
		}else{
			$this->view_data['print_pre_assessment'] = function($b){return NULL;};
		}

		if(in_array($this->current_session_user,$this->applicant_update_payment))
		{
			$this->view_data['applicant_update_payment'] = function($e_id){return '<li><a href="'.site_url('applicant/assessment_fee_update/'.$e_id).'">Assessment Fee Payment Center</a></li>';};
		}else{
			$this->view_data['applicant_update_payment'] = function($b){return NULL;};
		}

		if(in_array($this->current_session_user,$this->applicant_recieve_payment))
		{
			$this->view_data['print_assessment_or'] = function($e_id){return '<li><a href="'.site_url('pdf/assessment_or/'.$e_id).'" target="_blank">Print OR for Assessment Fee</a></li>';};
		}else{
			$this->view_data['print_assessment_or'] = function($b){return NULL;};
		}

		if(in_array($this->current_session_user,$this->enrollment_registrar))
		{
			$this->view_data['enrollment_registrar'] = function($e_id){return '<li><a href="http://westfields-enrollment.151272810036809.info/new_student/'.$e_id.'" target="_blank">Fill Enrollment Form</a></li>';};
		}else{
			$this->view_data['enrollment_registrar'] = function($b){return NULL;};
		}

		if(in_array($this->current_session_user,$this->student_reservation_payment))
		{
			$this->view_data['student_reservation_payment'] = function($e_id){return '<li><a href="'.site_url('fees/registration_fee/'.$e_id).'">Reservation Payment Center</a></li>';};
		}else{
			$this->view_data['student_reservation_payment'] = function($b){return NULL;};
		}
	}
	
	public function enrollmentsummary()
	{
		$this->view_data['verified']['count'] = $this->ms->count_all_students_per_grade_level();
		$this->view_data['verified']['pre']['male'] = $this->ms->count_students_by_level_type('male','preschool');
		$this->view_data['verified']['pre']['female'] = $this->ms->count_students_by_level_type('female','preschool');
		$this->view_data['verified']['low']['male'] = $this->ms->count_students_by_level_type('male',['lowschool']);
		$this->view_data['verified']['low']['female'] = $this->ms->count_students_by_level_type('female',['lowschool']);
		$this->view_data['verified']['upp']['male'] = $this->ms->count_students_by_level_type('male','uppschool');
		$this->view_data['verified']['upp']['female'] = $this->ms->count_students_by_level_type('female','uppschool');
		$this->view_data['verified']['hs']['male'] = $this->ms->count_students_by_level_type('male','highschool');
		$this->view_data['verified']['hs']['female'] = $this->ms->count_students_by_level_type('female','highschool');
		
		$this->view_data['unverified']['count'] = $this->ms->count_all_students_per_grade_level(TRUE);
		$this->view_data['unverified']['pre']['male'] = $this->ms->count_students_by_level_type('male',['preschool'],TRUE);
		$this->view_data['unverified']['pre']['female'] = $this->ms->count_students_by_level_type('female',['preschool'],TRUE);
		$this->view_data['unverified']['low']['male'] = $this->ms->count_students_by_level_type('male',['lowschool'],TRUE);
		$this->view_data['unverified']['low']['female'] = $this->ms->count_students_by_level_type('female',['lowschool'],TRUE);
		$this->view_data['unverified']['upp']['male'] = $this->ms->count_students_by_level_type('male',['uppschool'],TRUE);
		$this->view_data['unverified']['upp']['female'] = $this->ms->count_students_by_level_type('female',['uppschool'],TRUE);
		$this->view_data['unverified']['hs']['male'] = $this->ms->count_students_by_level_type('male',['highschool'],TRUE);
		$this->view_data['unverified']['hs']['female'] = $this->ms->count_students_by_level_type('female',['highschool'],TRUE);
	}
	
	public function siblings($type = 'mothername',$lastname = 'a')
	{
		$a_z = range('a','z');
		
		$this->pagnate_config['full_tag_open'] = '<div class="pagination"><ul>';
		$this->pagnate_config['num_links'] = 4;
		// $this->pagnate_config['display_pages'] = FALSE;
		$this->pagnate_config['base_url'] = base_url().$this->router->class.'/'.$this->router->method.'/'.$type.'/'.$lastname;
		$this->pagnate_config['per_page'] = 12;
		$this->pagnate_config["uri_segment"] = 5;
		$this->load->library('pagination');
		$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
		$this->pagnate_config['total_rows'] = $this->ms->count_siblings($type,$lastname,$this->pagnate_config['per_page'],$page);
		$this->pagination->initialize($this->pagnate_config);
		$this->view_data['pagnatelinks'] = $this->pagination->create_links();

		$this->view_data['siblings'] = $this->ms->get_siblings($type,$lastname,$this->pagnate_config['per_page'],$page);
		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $lastname;
		$this->view_data['p_link'] = $this->router->class.'/'.$this->router->method.'/'.$type;
		$this->view_data['active_type'] = $type;
	}
	
	public function contacts($lastname = 'all')
	{
		
		$a_z = range('a','z');
		array_unshift($a_z, 'all');

		$this->pagnate_config['full_tag_open'] = '<div class="pagination"><ul>';
		$this->pagnate_config['num_links'] = 4;
		// $this->pagnate_config['display_pages'] = FALSE;
		$this->pagnate_config['base_url'] = base_url().$this->router->class.'/'.$this->router->method.'/'.$lastname;
		$this->pagnate_config['per_page'] = 12;
		$this->pagnate_config["uri_segment"] = 4;
		$this->load->library('pagination');
		$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
		$this->pagnate_config['total_rows'] = $this->ms->count_contacts($lastname);
		$this->pagination->initialize($this->pagnate_config);
		$this->view_data['pagnatelinks'] = $this->pagination->create_links();

		$this->view_data['contacts'] = $this->ms->get_contacts($this->pagnate_config['per_page'],$page,$lastname);

		$this->view_data['a_z'] = $a_z;
		$this->view_data['active'] = $lastname;
		$this->view_data['p_link'] = $this->router->class.'/'.$this->router->method;
		$this->view_data['hashlink'] = $this->authlink->hash_make('keyToExportCSV');

	}
}